/**  
* @Title: SysController.java
* @Package com.lemon.controller.cityRun
* @Description: (一句话阐述):
* @author Ran_cc
* @date 2018年11月8日
* @version V1.0  
*/
package com.lemon.controller.crwx;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.lemon.conf.MyException;
import com.lemon.conf.MyInterceptor.LoginRequired;
import com.lemon.conf.redis.RedisUtil;
import com.lemon.model.cityRun.CrSysFeedBook;
import com.lemon.model.cityRun.CrSysProtocol;
import com.lemon.service.cityRun.CrShopUserService;
import com.lemon.service.cityRun.CrSysFeedBookService;
import com.lemon.utils.ReqResult;

/**
 * <p>Title: SysController</p>
 * <p>Description: 
 * </p>
 * <p>Company: </p>
 * @author Ran_cc
 * @date 2018年11月8日
 * @版本 V 1.0 
 */
@RestController
@RequestMapping("/xsys")
public class WxSysController {

	@Resource
	private CrSysFeedBookService feedService;

	@Resource
	private CrShopUserService uService;

	/**
	 * <b>Description:<blockquote>设置系统平台基本信息
	 * </blockquote></b>
	 * 
	 * @Title: addAdminUserInfo
	 * @param user
	 * @param request
	 * @param response
	 * @return
	 * @author Ran_cc
	 * @date 2018年10月18日
	 */
	@RequestMapping(value = "/getSysSet" , method = RequestMethod.POST)
	public ReqResult getShopTranSet(HttpServletRequest request , HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {
			String string = RedisUtil.get(RedisUtil.key_before + "setting");
			JSONObject js = ((JSONObject) JSONObject.parse(string)).getJSONObject("sets").getJSONObject("sysSet");
			reqResult.setReturnResult(js);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "设置系统平台基本信息");
		}
		return reqResult;
	}


	@RequestMapping(value = "/addSysFeedBack.do" , method = RequestMethod.POST)
	public ReqResult addSysFeedBack(@ModelAttribute CrSysFeedBook feedBook , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {

			feedBook.setStatus(1);
			int list = feedService.addFeedBookBySelective(feedBook);
			reqResult.setReturnResult(list);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "修改意见信息异常");
		}
		return reqResult;
	}


	///////////////////////////////关于协议和说明/////////////////////////////////////////
	@RequestMapping(value = "/getSysProtocolList" , method = RequestMethod.POST)
	public ReqResult getSysProtocolList(@ModelAttribute CrSysProtocol pro , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {
			pro.setStatus(1);
			List<CrSysProtocol> list = feedService.selectProtocolListBySelective(pro);
			reqResult.setReturnResult(list);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "修改意见信息异常");
		}
		return reqResult;
	}

	@RequestMapping(value = "/getSysProtocolById" , method = RequestMethod.POST)
	public ReqResult getSysProtocolById(@ModelAttribute CrSysProtocol pro , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {
			CrSysProtocol list = feedService.selectProtocolBySelective(pro);
			reqResult.setReturnResult(list);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "修改意见信息异常");
		}
		return reqResult;
	}

	@LoginRequired
	@RequestMapping(value = "/addSysProtocol.do" , method = RequestMethod.POST)
	public ReqResult addSysProtocol(@ModelAttribute CrSysProtocol pro , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {
			pro.setStatus(1);
			int list = feedService.insertProtocolBySelective(pro);
			reqResult.setReturnResult(list);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "修改意见信息异常");
		}
		return reqResult;
	}

	@LoginRequired
	@RequestMapping(value = "/updateSysProtocol.do" , method = RequestMethod.POST)
	public ReqResult updateSysProtocol(@ModelAttribute CrSysProtocol pro , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {
			int list = feedService.updateProtocolBySelective(pro);
			reqResult.setReturnResult(list);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "修改意见信息异常");
		}
		return reqResult;
	}
}
